<?php
namespace Api\Model;
use Think\Model;

class NewsModel extends Model {
	private $_db='';
	public function __construct(){
		$this->_db=M('news');
	}
	public function getNewsList($data,$page,$pageSize) {
		$conditions = $data;
		if(isset($data['title']) && $data['title']){
			$conditions['title'] = array ('like','%'.$data['title'].'%');
		}
		if(isset($data['catid']) && $data['catid']){
			$conditions['catid'] = intval($data['catid']);
		}
		$offset = ($page - 1) * $pageSize;
		$list = $this->_db->where($conditions)->order('listorder desc, news_id desc')->limit($offset,$pageSize)->select();
	
		return $list;
	}
	
	public function getNewsById($id)
	{
		if(!is_numeric($id) || !$id){
			throw_exception("id不存在或非法");
		}
		$data = $this ->_db->where('news_id='.$id)->find();
		return $data;
	}
}